package cn.huaguo.domain.order.service;

import cn.huaguo.domain.order.model.entity.OrderEntity;
import cn.huaguo.domain.order.repository.IOrderRepository;
import cn.huaguo.types.context.BaseContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：Arvin
 * @description：订单实现
 * @Date：2024/5/14 13:59
 */
@Service
public class OrderService implements IOrderService {
    @Resource
    private IOrderRepository orderRepository;

    /**
     * 新增订单
     *
     * @param orderEntity
     */
    @Override
    public void addOrder(OrderEntity orderEntity) {

        orderEntity.setCreateUserId(BaseContext.getCurrentId());
        orderRepository.addOrder(orderEntity);
    }

    /**
     * 根据创建订单人Id查询订单
     *
     * @param userId
     * @return
     */
    @Override
    public List<OrderEntity> queryOrderInfoById(String userId) {
        List<OrderEntity> orderEntityList = orderRepository.queryOrderInfoByCreateUserId(userId);
        return orderEntityList;
    }

    /**
     * 根据TasKId更新OrderStatus
     *
     * @param taskId
     * @return
     */
    @Override
    public Boolean updateOrderStatus(String taskId, String orderStatus) {
        return orderRepository.updateOrderStatus(taskId, orderStatus);
    }

    /**
     * 订单取消退款
     *
     * @param taskId
     * @param orderStatus
     * @return
     */
    @Override
    public Boolean refund(String taskId, String orderStatus) {
        return orderRepository.updateOrderStatus(taskId, orderStatus);
    }
}
